Using 'make' for backups
Thanks to Lars Weiler for providing this tip.
Usualy make from sys-devel/make is known as a tool for compiling applications. But it could also be used to provide often used commands so that they can be accessed easily.
Quite everybody wants to do backups. This could be done by packing them with tar. For instance, we want to pack the ~/Mail folder and name the file with a date:
Code Listing 1: tar ~/Mail with date included
$ tar cvjf ~/Backups/Mail-`date +%F`.tar.bz2 ~/Mail
After that we copy that file (and possibly more) to another computer by using rsync and delete all the files in ~/Backups afterwards:
Code Listing 2: Copy backup-file to another computer with rsync
$ rsync -avute ssh ~/Backups/ user@othermachine:~/Backups/
% rm ~/Backups/*
And now comes the clue with make. After a week you already forgot the commands. Why not store them in a Makefile located in the home-directory, so that you only have to call make backup?
Inside the Makefile (beware of the uppercased 'M') we provide two targets for the commands, so that we can call them separately, e.g. if you only want to copy the files. The first target backup will only call the other targets in the given order:
Code Listing 3: Sample Makefile for backups
backup: compress copy
compress:
tar cvjf ~/Backups/Mail-`date +%F`.tar.bz2 ~/Mail
copy:
rsync -avute ssh ~/Backups/ user@othermachine:~/Backups/
rm ~/Backups/*
Now we can call make backup in the home directory and the ~/Mail-folder will be compressed and copied to the other computer. The restore-command-set will be your homework ;-)
Of course, there is a wide use for batched processes with Makefiles. Think about all the things you ever wanted to have scripted with easy usability. You can find more instructions in the info make pages.
rate this article:current rating: average rating: 1.3 (51 votes) (1=very good 6=terrible)
Your rating:
back